/**
 * Created by Administrator on 2018/1/18.
 */
layui.use(['jquery','form','layer'], function(){
    var $ = layui.jquery,
        layer = layui.layer,
        form = layui.form;

    var min = $('#min').val();
    var money = $('#money').val();

    //自定义验证规则
    form.verify({
        apply_money: function(value){

            if(value <= 0){
                return '提取金额不能为负数和零';
            }

            if(value > 0 && value < Number(min) ){
                return '提取金额不能小于'+min;
            }

            if(value > Number(money))
            {
                return '可提取金额不足';
            }
        }
    });

    //监听表单提交
    form.on('submit(demo1)', function(data){
        post_data = data.field;
        $.ajax({
            type: "POST",
            url: '/user/brokerage_apply',
            data: post_data,
            dataType: "json",
            success: function(data){
                if(data.code==200){
                    //父页面弹出layer
                    layer.msg(data.msg,{
                        icon:1,
                        shade: 0.3,
                        btn: ['我知道了'],
                        btnAlign: 'c',
                        time:10000
                    },function(){

                        window.location.href = location.href;
                    });
                }else{
                    layer.msg(data.msg);
                }
            }
        });
        return false;
    });

});
